feat: Add tool annotations for improved LLM tool understanding#144
feat: Add tool annotations for improved LLM tool understanding#144bryankthompson wants to merge 1 commit intobrowserbase:mainfrom
Conversation
Add readOnlyHint and destructiveHint annotations to all tools to help LLMs better understand tool behavior and make safer decisions. Changes: - Added ToolAnnotations import and annotations field to ToolSchema type - Added destructiveHint: true to navigation and action tools: - browserbase_stagehand_navigate (changes page state) - browserbase_session_create (creates resources) - browserbase_session_close (destroys resources) - browserbase_stagehand_act (performs page actions) - browserbase_stagehand_agent (autonomous actions) - Added readOnlyHint: true to read-only tools: - browserbase_stagehand_extract (data extraction) - browserbase_stagehand_observe (element observation) - browserbase_stagehand_get_url (URL query) - browserbase_screenshot (captures current state) - Added title annotations for human-readable display - Updated index.ts to pass annotations when registering tools This improves tool safety metadata for MCP clients. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Greptile SummaryThis PR adds MCP tool annotations to all 9 browser automation tools, providing semantic metadata that helps LLMs make safer and more informed tool execution decisions. The implementation correctly categorizes tools as read-only (extract, observe, get_url, screenshot) or destructive (navigate, act, agent, session_create, session_close) based on their actual behavior. Key Changes:
Benefits:
The implementation is clean, well-structured, and follows MCP SDK patterns correctly. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant LLM
participant MCPServer as MCP Server
participant Smithery as Smithery Tool Handler
participant Tool as Tool Implementation
participant Browser as Browserbase
Note over LLM,Browser: Tool Registration Flow
MCPServer->>Tool: Load tool definitions
Tool->>Tool: Add annotations (title, readOnlyHint/destructiveHint)
Tool-->>MCPServer: Return ToolSchema with annotations
MCPServer->>Smithery: Register tool with annotations
Note over Smithery: Stores metadata:<br/>- name<br/>- description<br/>- inputSchema<br/>- annotations
Note over LLM,Browser: Tool Execution Flow (with annotation awareness)
LLM->>LLM: Analyze available tools with annotations
Note over LLM: Prefers readOnlyHint tools for<br/>information gathering
LLM->>MCPServer: Call tool (e.g., browserbase_stagehand_extract)
MCPServer->>Smithery: Route to tool handler
Smithery->>Tool: Execute with params
Tool->>Browser: Perform operation (read/write based on annotation)
Browser-->>Tool: Return result
Tool-->>Smithery: Return ToolResult
Smithery-->>MCPServer: Return content
MCPServer-->>LLM: Return result with awareness of operation safety
|
Greptile found no issues!From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
Summary
Adds MCP tool annotations (
readOnlyHint,destructiveHint,title) to all 9 tools to help LLMs better understand tool behavior and make safer decisions about tool execution.Changes
Type Updates
ToolAnnotationsimport from@modelcontextprotocol/sdk/types.jsToolSchematype to include optionalannotationsfieldindex.tsto pass annotations when registering tools with the serverTools Annotated
Destructive tools (
destructiveHint: true):browserbase_stagehand_navigatebrowserbase_session_createbrowserbase_session_closebrowserbase_stagehand_actbrowserbase_stagehand_agentRead-only tools (
readOnlyHint: true):browserbase_stagehand_extractbrowserbase_stagehand_observebrowserbase_stagehand_get_urlbrowserbase_screenshotWhy This Matters
titleannotation provides cleaner names for tool displayTesting
Before/After Example
Before:
After:
🤖 Generated with Claude Code